<?php
namespace app\index\controller;

use think\Controller;
use \think\facade\Hook;
use think\queue\Worker;

class Index extends Controller
{
    public function index()
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改（2006-2018） - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
    }

    public function hello($name = 'ThinkPHP5')
    {
        return 'hello,' . $name;
    }

    public function tree()
    {
        $menu = db('rbac_node')->select();
        $data = [];
        foreach ($menu as $k => $v) {
            $data[] = [
                'id' => $v['id'],
                'pId' => $v['parent_id'],
                'name' => $v['node_name']
            ];
        }
        $this->assign('data', json_encode($data));
        return view('tree');
    }

    /**
     * 99乘法表
     */
    public function x9()
    {
        $j = 1;
        while ($j <= 9) {
            $i = 1;
            while ($i <= $j) {
                echo "{$i}x{$j}=" . ($i * $j) . " ";
                $i++;
            }
            echo "<br />";
            $j++;
        }
    }

    /**
     * 冒泡排序
     */
    public function js()
    {
        $a = array(3, 8, 1, 4, 85, 7);
        $len = count($a);
        for ($i = 0; $i < $len - 1; $i++) {
            dump(1);
            for ($j = 0; $j < $len - $i - 1; $j++) {
                if ($a[$j] > $a[$j + 1]) {
                    $temp = $a[$j];
                    $a[$j] = $a[$j + 1];
                    $a[$j + 1] = $temp;
                }
                dump($a);
            }
        }
    }
    public function ms($uid)
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        $name = "test";
        $num = 18;
        if($redis->lLen($name)<$num){
            $user_list = $redis->Lrange($name,0,$num);
            //如果为真，则往队列新增
            if(!in_array($uid,$user_list)){
                $redis->lPush($name,$uid);
            }else{
                echo "您已经抢过了";
            }
        }else{
            echo "已经被抢光";
        }
        $user_list = $redis->Lrange($name,0,$num);
        dump($user_list);
    }

    /**
     * @author ASUS
     * @date 2020-10-12 13:48
     * 算法
     */
    public function test()
    {
        $nums = [2,7,11,15];
        $tag = 13;
        $count = count($nums);
        for ($i=0;$i<$count;$i++){
            for ($j=$i+1;$j<$count;$j++){
                if($nums[$i]+$nums[$j]==$tag){
                    $a = [$i,$j];
                }
            }
        }
        dump($a);
    }
}
